package com.wkhyapp.lm.weigit.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.NumberPicker;

import com.wkhyapp.lm.R;
import com.wkhyapp.lm.adapter.CategoryAdapter;
import com.wkhyapp.lm.http.vo.Category;

import java.util.List;

/**
 * Created by fang on 2021/10/19.
 */

public class CategoryPickerDialg {

    private Dialog mDialog;
    private List<String> categories;
    private Context mContext;
    private View dialog_view;
    private CategoryAdapter categoryAdapter;
    public CategoryDialog.callBack mCallBack;
    private NumberPicker picker;

    public CategoryPickerDialg(Context context, List<String> categories) {
        this.mContext = context;
        this.categories = categories;
        init();
    }

    public void init() {
        //   categoryAdapter  = new CategoryAdapter(mContext,categories, R.layout.item_category);
        mDialog = new Dialog(mContext, R.style.custom_dialog);
        dialog_view = LayoutInflater.from(mContext).inflate(R.layout.dialog_picker, null);
        picker = (NumberPicker) dialog_view.findViewById(R.id.picker);
        String[] datas = new String[]{"北京", "上海", "广州", "深圳"};
        picker.setDisplayedValues(datas); //设置文字
        picker.setMaxValue(datas.length - 1); //设置最大值，最大值是datas[3]
        mDialog.setContentView(dialog_view);

       // categoryAdapter.notifyDataSetChanged();
        Window window = mDialog.getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.BOTTOM; // 居中位置
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);


    }

    public void close() {
        mDialog.dismiss();
    }

    public void show() {
        mDialog.show();
    }

    public void setCallBack(CategoryDialog.callBack callBack) {
        this.mCallBack = callBack;
    }


    public interface callBack {
        void jump(Category item);
    }
}